let select = [];
for(let i = 0; i<8; i++){
  select.push(Math.round(Math.random()*20 + 1));
}

sortFn(select);
console.log(select)
function sortFn(arr){
  let len = arr.length;
  let temp;
  let index;
  for(let i = 0; i<len - 1; i++){
    index = i;
    for(let j = i + 1; j<len; j++){
      if(arr[index] > arr[j]){
        index = j;  //记录下标，用于跟后面比较
      }
    }
    //交换
    temp = arr[i];
    arr[i] = arr[index];
    arr[index] = temp;
  }
}

